package game.element;

import game.utility.ResourceUtility;

import java.awt.Graphics2D;
import java.awt.Image;

public abstract class ImageGameElement extends AbstractGameElement {

	private Image image;

	public ImageGameElement(int x, int y, int width, int height) {
		super(x, y, width, height);
	}

	public ImageGameElement(int x, int y, String imageSource) {
		this.image = ResourceUtility.getBufferedImage(imageSource);
	}

	@Override
	public void drawToGraphics(Graphics2D g2d, int offsetX, int offsetY) {
		if (isVisible()) {
			if (image == null) {
				throw new RuntimeException("Missing image for class: " + getClass().getSimpleName());
			}
			g2d.drawImage(image, getX() + offsetX, getY() + offsetY, getWidth(), getHeight(), null);
		}
	}

	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}
}